<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title>长约合同起草</title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            // $('#status').combobox('setValue', '0');
                            // 初始化长约合同起草列表
                            bindgrid();
                            // 初始化虚拟合同起草列表
                            setchDraftsDataGrid()

                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                        });
                        // 导出为Excel
                        function exportDraftList() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            let status = $('#status').combobox('getValue')
                            var form = [];
                            form.push('startTime=' + (startTime ? startTime : ''));
                            form.push('endTime=' + (endTime ? endTime : ''));
                            form.push('status=' + (status ? status : ''));
                            form.push('longTerm=1');

                            let url = 'api/sale/contract/draft/export'
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                            xhr.setRequestHeader('token', localStorage.getItem('token'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = '合同起草' + new Date().getTime() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }

                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        input:disabled {
                            background-color: #dae1ed;
                        }

                        a {
                            text-decoration: none
                        }

                        /*.table tr {
            height: 15px;
        }*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label> <input
                                    class="easyui-combobox" id="status" name="status" style="width: 80px" data-options="valueField: 'value',
		                  textField: 'label',
		                  editable:false,
		                  panelHeight:'auto',
		                  data: [{
			                   label: '全部',
			                   value: ''
		                       },{
		                       label: '待提交',
			value: '0',
			selected:true
		},{
			label: '已提交',
			value: '1'
		},{
			label: '已完成',
			value: '2'
		}]">
                                <%-- <option value="">
                                    </option>
                                    <option value="0">待提交</option>
                                    <option value="1">已提交</option>--%>
                                    </select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                        class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                        onclick="selectList()">查询</a>
                                    <a id="export" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-export'" onclick="exportDraftList()">导出</a>
                        </div>
                        <table id="dg"></table>
                        <%-- 新增合同起草 --%>
                            <div id="add" class="easyui-window" closed="true" modal="true" title="长约合同起草"
                                style="width: 900px; height: 430px; padding: 10px 20px;top:50px">
                                <form id="fm" class="ssec-form">
                                    <div id="tabs" class="easyui-tabs" style="width: 855px; height: 350px">
                                        <div title="基本信息" style="padding: 5px;">
                                            <table class="table">
                                                <!-- 模板id-->
                                                <!--   <input id="temId" class="easyui-validatebox textbox" data-options="required:false"
                                  name="temId"
                                  type="hidden"/>
                          <td>
                               <div class="ssec-label">模板名称：</div>
                           </td>
                           <td>
                               <div class="ssec-text normal">
                                   <input id="temName" name="temName"
                                          class="easyui-validatebox textbox" data-options="required:true"/>
                               </div>
                           </td>-->
                                                <tr>
                                                    <td>
                                                        <!-- 长约合同起草id-->
                                                        <input type="hidden" class="easyui-validatebox textbox"
                                                            data-options="required:false" id="draId" name="draId" />
                                                        <div class="ssec-label">长约合同编号：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draCode" name="draCode"
                                                                class="easyui-validatebox textbox"
                                                                data-options="disabled:true,required:false" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>

                                                    <td>
                                                        <!-- 虚拟合同起草id-->
                                                        <input type="hidden" class="easyui-validatebox textbox"
                                                            data-options="required:false" id="oldDraId"
                                                            name="oldDraId" />
                                                        <div class="ssec-label">虚拟合同编号：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal"
                                                            onclick=" $('#selectDraftWindow').window('open')">
                                                            <input id="oldDraCode" name="oldDraCode"
                                                                class="easyui-textbox"
                                                                data-options="disabled:true,required:false,prompt:'点击选择虚拟合同信息'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">合同名称：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draName" name="draName"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">运输方式：</div>
                                                    </td>
                                                    <td>

                                                        <div class="ssec-text normal">
                                                            <input id="draTransportName" name="draTransportName"
                                                                style="width: 170px" class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=运输方式',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">销售组织：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draOrgCode" name="draOrgCode"
                                                                style="width: 170px" class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=销售组织',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto',onSelect: function (record) {
			                                                                      //根据选择的销售组织后，改变某些字段的值
                                                                                   changeElementByDraOrgCode(record)
                                                                                  }" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">合同金额：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draMoney" name="draMoney" style="width: 95px"
                                                                class="easyui-numberbox"
                                                                data-options="required:true,precision:3" />
                                                            <input id="daCurrency" name="daCurrency" style="width: 70px"
                                                                class="easyui-combobox" data-options="required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto',onSelect:function(record){
					                                                         setExchangeRate(record)
					                                                         }" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">税率(%)：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draTax" name="draTax" style="width: 170px"
                                                                class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=税码',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <%-- <td>
                                                        <div class="ssec-label">是否内贸：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draIsIn" name="draIsIn" style="width: 170px"
                                                                    class="easyui-combobox" data-options="valueField: 'value',textField: 'label', editable:false,
                                                                                  panelHeight:'auto',data: [{label: '是',value: '1',selected:true},{
                                                                                  label: '否', value: '0'}]" />
                                                            </div>
                                                        </td>--%>
                                                        <td>
                                                            <div class="ssec-label">结算方式：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draSettleName" name="draSettleName"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=结算方式',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">汇率：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draRate" name="draRate" style="width: 170px"
                                                                    class="easyui-numberbox"
                                                                    data-options="disabled:true,editable:false,required:true,precision:3" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">销售凭证类型：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draVouchaer" name="draVouchaer"
                                                                    class="easyui-textbox"
                                                                    data-options="disabled:true,required:true" />
                                                            </div>
                                                        </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">客商名称：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infName" name="infName" class="easyui-textbox"
                                                                data-options="disabled:true,required:true,readonly:true,prompt:'点击选择客商信息'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">客商编码：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infCode" name="infCode"
                                                                class="easyui-validatebox textbox"
                                                                data-options="disabled:true,required:true" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">法定代表人：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infLegalPerson" name="infLegalPerson"
                                                                class="easyui-validatebox textbox"
                                                                data-options="disabled:true,required:false" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">客商代办人：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infHandlePerson" name="infHandlePerson"
                                                                class="easyui-validatebox textbox"
                                                                data-options="disabled:true,required:false" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">代办人联系方式：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infTel" name="infTel" class="easyui-numberbox"
                                                                data-options="required:false" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">客户国家：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="infCountry" name="infCountry"
                                                                class="easyui-textbox"
                                                                data-options="disabled:true,required:false" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">客户级别：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="classificationDescr" name="classificationDescr"
                                                                class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=客户分类',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">销售地区：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draSaleAreaCode" name="draSaleAreaCode"
                                                                class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=销售地区',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">合同签订日期：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draSignTime" name="draSignTime"
                                                                style="width: 170px" class="easyui-datetimebox"
                                                                data-options="required:true,parser:myparserDateTime" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>

                                                    <td>
                                                        <div class="ssec-label">合同起始日期：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draStartTime" name="draStartTime"
                                                                style="width: 170px" class="easyui-datetimebox"
                                                                data-options="disabled:false,required:true" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">合同终止日期：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draEndTime" name="draEndTime"
                                                                style="width: 170px" class="easyui-datetimebox"
                                                                data-options="disabled:false,required:true" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">外贸术语：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draTerminologyForeignTradeName"
                                                                name="draTerminologyForeignTradeName"
                                                                style="width: 170px" class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=国际外贸条款',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>

                                                    <!-- oa用户id -->
                                                    <input id="oaUserId" name="oaUserId" type="hidden"
                                                        class="easyui-validatebox textbox"
                                                        data-options="required:false" />
                                                    <!-- oa流程id -->
                                                    <input id="oaWfId" name="oaWfId" type="hidden"
                                                        class="easyui-validatebox textbox"
                                                        data-options="required:false" />

                                                    <%-- <td>
                                                        <div class="ssec-label">海运费货币：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draSeaCurrency" name="draSeaCurrency"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
                                                                              valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>--%>
                                                </tr>
                                                <%-- <tr>
                                                    <td>
                                                        <div class="ssec-label">收付款协议：</div>
                                                    </td>
                                                    <td>

                                                        <div class="ssec-text normal">
                                                            <input id="draAgreementName" name="draAgreementName"
                                                                class="easyui-validatebox textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>



                                                    </tr>--%>
                                                    <tr>

                                                        <td>
                                                            <div class="ssec-label">分销渠道：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draChannelCode" name="draChannelCode"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=分销渠道',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">产品组：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draGroup" name="draGroup"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=产品组',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">到货地址：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draAddress" name="draAddress"
                                                                    class="easyui-combogrid" data-options="disabled:true,required:true,
            panelWidth: 400,
			idField: 'dicValue',
			textField: 'dicName',
			url: 'sysDict/queryAddress',
			delay: 500,
            mode: 'remote',
			 queryParams: {
                    dicName: '送货地址',
                },
			columns: [[
				{field:'dicName',title:'地址名称',width:180},
				{field:'dicValue',title:'地址代码',width:100},
			]],
			fitColumns: true" />
                                                            </div>
                                                        </td>

                                                    </tr>
                                                    <tr>

                                                        <td>
                                                            <div class="ssec-label">到货详细地址：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draAddressDetail" name="draAddressDetail"
                                                                    class="easyui-textbox"
                                                                    data-options="disabled:true,required:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">是否按计划数核算：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draIsPlanAccounting"
                                                                    name="draIsPlanAccounting" style="width: 170px"
                                                                    class="easyui-combobox"
                                                                    data-options="disabled:true,required:true,valueField:'value',textField:'label',panelHeight:'auto', editable:false,panelHeight:'auto',data: [{label: '是',value: '1',selected:true },{ label: '否', value: '0' }]" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">收款条件：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draProceedsName" name="draProceedsName"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=收款条件',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">是否长约：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="longTerm" name="longTerm"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,valueField: 'value',textField: 'label', editable:false,
		                                                                         panelHeight:'auto',data: [{label: '否',value: '0'},{
			                                                                     label: '是', value: '1'}], onSelect: function (record) {}" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">合同类型：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draTypeId" name="draTypeId"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,valueField: 'value',textField: 'label', editable:false,
		                                                                         panelHeight:'auto',data: [{label: '非贸易',value: '0'},{
			                                                                     label: '贸易', value: '1'}], onSelect: function (record) {
			                                                                      //数据加载完毕事件
                                                                                   changeDisplay(record)
                                                                                  }" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label draTypeFlag">是否创建采购订单：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal draTypeFlag">
                                                                <input id="draCreateOrderFlag" name="draCreateOrderFlag"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,required:false,valueField: 'value',textField: 'label', editable:false,
		                                                                         panelHeight:'auto',data: [{label: '否',value: '0'},{
			                                                                     label: '是', value: 'X',selected:true}]" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr class="draTypeFlag">
                                                        <td>
                                                            <div class="ssec-label ">币种：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draCurrencyTrade" name="draCurrencyTrade"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">供应商：
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <input type="hidden" id="draSupplyId"
                                                                class="easyui-validatebox textbox">
                                                            <div class="ssec-text normal">
                                                                <input id="draSupply" name="draSupply"
                                                                    style="width: 170px" class="easyui-textbox"
                                                                    data-options="disabled:true,readonly:true,required:false,prompt:'点击选择客商信息'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">是否进厂：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draIntoPlant" name="draIntoPlant"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=是否进厂',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto',onSelect: function (record) {
			                                                                      //数据加载完毕事件
                                                                                   changeWeighFlag(record)
                                                                                  }" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr class="draTypeFlag">
                                                        <td>
                                                            <div class="ssec-label">是否过磅：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draWeighFlag" name="draWeighFlag"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=是否过磅',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">采购组：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPurchaseOrg" name="draPurchaseOrg"
                                                                    style="width: 170px" class="easyui-textbox"
                                                                    data-options="required:false,disabled:true" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">是否自提：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPackUp" name="draPackUp"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=是否自提',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'100'" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr class="draTypeFlag">
                                                        <td>
                                                            <div class="ssec-label">付款条件：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPaymentName" name="draPaymentName"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=付款条件',method:'get',
					                                                          valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                        <td>

                                                            <div class="ssec-label">采购金额 ：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPurchaseTotalAmount"
                                                                    name="draPurchaseTotalAmount" style="width: 170px"
                                                                    class="easyui-numberbox"
                                                                    data-options="required:false,precision:3" />
                                                            </div>
                                                        </td>
                                                        <td>

                                                            <div class="ssec-label">运输总成本 ：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draTransportTotalCost"
                                                                    name="draTransportTotalCost" style="width: 170px"
                                                                    class="easyui-numberbox"
                                                                    data-options="disabled:true,required:false,precision:3" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr class="draTypeFlag">

                                                        <%-- <td>

                                                            <div class="ssec-label">包装总成本 ：</div>
                                                            </td>
                                                            <td>
                                                                <div class="ssec-text normal">
                                                                    <input id="draPackAgeTotalCost"
                                                                        name="draPackAgeTotalCost" style="width: 170px"
                                                                        class="easyui-numberbox"
                                                                        data-options="required:false" />
                                                                </div>
                                                            </td>--%>

                                                    </tr>
                                                    <tr class="draTypeFlag">
                                                        <td>

                                                            <div class="ssec-label">采购总数 ：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPurchaseTotalCount"
                                                                    name="draPurchaseTotalCount" style="width: 170px"
                                                                    class="easyui-numberbox"
                                                                    data-options="disabled:true,required:false,precision:3" />
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-label">结算标识：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draSettleFlag" name="draSettleFlag"
                                                                    style="width: 170px" class="easyui-combobox"
                                                                    data-options="disabled:true,editable:false,required:false,url:'sysDict/queryItemByTypeName?dicName=结算标识',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div class="ssec-label">计划完成发货日期：</div>
                                                        </td>
                                                        <td>
                                                            <div class="ssec-text normal">
                                                                <input id="draPlanCompleteDeliveryTime"
                                                                    name="draPlanCompleteDeliveryTime"
                                                                    style="width: 170px" class="easyui-datetimebox"
                                                                    data-options="required:false" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                            </table>
                                        </div>
                                        <div title="费用明细" style="padding: 5px;">
                                            <table class="table">
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">内陆运输总价：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draTransportMoney" name="draTransportMoney"
                                                                style="width: 95px" class="easyui-numberbox"
                                                                data-options="required:false,disabled:true,precision:3" />
                                                            <input id="draTransportCurrency" name="draTransportCurrency"
                                                                style="width: 70px" class="easyui-combobox"
                                                                data-options="editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">海运费：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draSeaMoney" name="draSeaMoney"
                                                                style="width: 95px" class="easyui-numberbox"
                                                                data-options="required:true,precision:3" />
                                                            <input id="draSeaCurrency" name="draSeaCurrency"
                                                                style="width: 70px" class="easyui-combobox"
                                                                data-options="disabled:true,editable:false,precision:3,required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">保险费：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draInsureMoney" name="draInsureMoney"
                                                                style="width: 95px" class="easyui-numberbox"
                                                                data-options="required:true,disabled:true,precision:2" />
                                                            <%-- 保险费货币--%>
                                                                <input id="draInsureCurrency" name="draInsureCurrency"
                                                                    style="width: 70px" class="easyui-combobox"
                                                                    data-options="editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>

                                                </tr>
                                                <tr>

                                                    <td>
                                                        <div class="ssec-label">佣金总额：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draCommisionMoney" name="draCommisionMoney"
                                                                style="width: 95px" class="easyui-numberbox"
                                                                data-options="required:false,disabled:true,precision:3" />
                                                            <input id="draCommisionCurrency" name="draCommisionCurrency"
                                                                style="width: 70px" class="easyui-combobox"
                                                                data-options="editable:false,required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">港杂费总额：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draOtherMoney" name="draOtherMoney"
                                                                style="width: 95px" class="easyui-numberbox"
                                                                data-options="required:false,precision:3" />
                                                            <input id="draOtherCurrency" name="draOtherCurrency"
                                                                style="width: 70px" class="easyui-combobox"
                                                                data-options="editable:false,precision:3,required:true,url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'" />
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-label">包装费：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="draPackageMoney" name="draPackageMoney"
                                                                style="width: 170px" class="easyui-numberbox"
                                                                data-options="editable:false,precision:3,required:true,disabled:true" />
                                                        </div>
                                                    </td>


                                                </tr>
                                            </table>
                                        </div>
                                        <div title="履行明细" style="padding: 5px;">
                                            <table id="product"></table>
                                        </div>
                                        <div title="附件" style="padding: 5px;">
                                            <table>
                                                <tr>
                                                    <td colspan="3">
                                                        <input type="button" id="uploadbtn" value="选择文件..." />
                                                        <input type="file" id="uploadpicker" accept=""
                                                            onchange="changeFile()" multiple style="display: none;" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <label style="width:40%;text-align:right;">附件下载：</label>
                                                        <ul id="checkfileList"></ul>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </form>
                                <div id="selectMMWindow" closed="true" modal="true" class="easyui-window" title="选择产品"
                                    style="width:730px;height: 370px;padding:10px;">
                                    <table id="mmDataGrid"></table>
                                </div>
                                <%-- <div id="selectdraBasicPriceWindow" closed="true" modal="true"
                                    class="easyui-window" title="基准价列表" --%>
                                    <%-- style="width:630px;height: 370px;padding:10px;">--%>
                                        <%-- <table id="draBasicPriceDataGrid"></table>--%>
                                            <%-- </div>--%>
                                                <%-- 选择客商的弹窗 --%>
                                                    <div id="selectCustomersWindow" class="easyui-window" closed="true"
                                                        modal="true" title="待选供应商"
                                                        style="width: 900px; height: 400px; padding: 5px 5px">
                                                        <%--待选供应商列表DataGrid --%>
                                                            <table id="customersDataGrid"></table>
                                                    </div>
                                                    <%-- 选择供应商的弹窗 --%>
                                                        <div id="selectSupplyWindow" class="easyui-window" closed="true"
                                                            modal="true" title="待选供应商"
                                                            style="width: 900px; height: 400px; padding: 5px 5px">
                                                            <%-- 去掉搜索 by 20220507 <div style="margin: 5px 0px">
                                                                &lt;%&ndash; 搜索框 &ndash;%&gt;
                                                                <label style="font-size: 12px;">创建时间：</label> <input
                                                                    class="easyui-datebox" name="startSupplyTime"
                                                                    id="startSupplyTime"
                                                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                                                    value="" style="width: 150px"> <label
                                                                    style="font-size: 10px;">~</label>
                                                                <input class="easyui-datebox" name="endSupplyTime"
                                                                    id="endSupplyTime"
                                                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                                                    style="width: 150px" /> </select> <a id="search"
                                                                    style="margin-left: 30px" href="javascript:void(0)"
                                                                    class="easyui-linkbutton"
                                                                    data-options="iconCls:'icon-search'"
                                                                    onclick="selectSupplyListByParams()">查询</a>
                                                        </div>--%>
                                                        <%--待选供应商列表DataGrid --%>
                                                            <table id="supplyDataGrid"></table>
                            </div>
                            <%-- 选择虚拟合同的弹窗 --%>
                                <div id="selectDraftWindow" class="easyui-window" closed="true" modal="true"
                                    title="虚拟合同列表" style="width: 900px; height: 430px; padding: 10px 20px">
                                    <!-- 搜索框 -->
                                    <label style="font-size:7px;">创建时间：</label>
                                    <input class="easyui-datebox" id="startDraftTime"
                                        data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                        value="" style="width:150px">
                                    <label style="font-size:10px;">~</label>
                                    <input class="easyui-datebox" id="endDraftTime"
                                        data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                        style="width:150px" />
                                    </select>
                                    <a style="margin-left: 30px" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-search'" onclick="selectVirtualList()">查询</a>
                                    <!--合同签署列表DataGrid  -->
                                    <table id="draftList"></table>
                                </div>
                    </div>
                    </div>
        </body>
        <script>
            var KCDD_URL = null
            var selectedFileList = [];//已选文件列表
            var succsessCount = 0;//上传成功文件个数
            var errorCount = 0;//上传失败文件个数
            var editIndex = undefined;
            // 销售组织（内贸）
            var marketingOrganizingIn = [
                '1100', '1110', '1300', '1310', '999B', '999C', '2110', '2210', '1700', '1130', '1120', '1140', '7000'
            ]
            // 销售组织（外贸）
            var marketingOrganizingOut = [
                '1200', '1210', '1400', '1220', '1230', '1240'
            ]
            // 新源的销售组织
            var marketingOrganizingOfXY = [
                '1100', '1200', '1300', '1400', '1700', '7000'
            ]
            // 思派的销售组织
            var marketingOrganizingOfSP = [
                '1110', '1210', '1310', '1410'
            ]
            // 湖北材料的销售组织
            var marketingOrganizingOfHB = [
                '1120', '1220'
            ]
            // 湖北浩科的销售组织
            var marketingOrganizingOfHK = [
                '1130', '1230'
            ]
            // 新蔚源的销售组织
            var marketingOrganizingOfXWY = [
                '1140', '1240'
            ]
            // 履行明细的列
            var productColumns = [
                {
                    field: 'draId',
                    title: '合同起草id',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'proId',
                    title: '产品Id',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'lineNumber',
                    title: '产品行号',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'mmTag',
                    title: '物料种类',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draSkuMmTemp',
                    title: '单个物料净重',
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'draSkuItemCount',
                    title: '单个sku物料净重',
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'skuNum',
                    title: 'SKU编码',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'skuDescription',
                    title: 'SKU描述',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'draCode',
                    title: '物料编码',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draName',
                    title: '物料描述',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draSpecs',
                    title: '规格',
                    editor: { type: 'textbox', options: { precision: 0 } },
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draUnit',
                    title: '计量单位',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draNum',
                    title: '数量',
                    sortable: true,
                    editor: { type: 'numberbox', options: { precision: 3, required: true } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0';
                    }
                },
                {
                    field: 'draPackageId',
                    title: '包装方式',
                    sortable: true,
                    editor: {
                        type: 'combobox',
                        options: {
                            url: 'sysDict/queryItemByTypeName?dicName=包装方式',
                            method: 'get',
                            valueField: "dicValue",
                            textField: "dicName",
                            editable: false,
                            required: true,
                            onSelect: function (record) {
                                let proRow = $('#product').datagrid('getSelected')
                                proRow.draRefusalCauseName = record.dicName
                            }
                        }
                    },
                    formatter: function (val, rec) {
                        return val ? unescape(rec.draPackageName) : '';
                    }
                },
                {
                    field: 'draPackageNum',
                    title: '包装数量',
                    sortable: true,
                    // editor: {required: true, type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0';
                    }
                },
                {
                    field: 'draPackExpense',
                    title: '包装费',
                    sortable: true,
                    // editor: {required: true, type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'draPackageCurrency',
                    title: '包装费货币',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(rec.draPackageCurrencyName) : '';
                    }
                },
                {
                    field: 'transportPrice',
                    title: '运费单价',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'realUnitTransportMonry',
                    title: '单吨运费',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },

                {
                    field: 'draPriceList',
                    title: '价目表名称',
                    hidden: true,
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }, {
                    field: 'draUnitPrice',
                    title: '原币含税单价',
                    editor: { type: 'numberbox', options: { precision: 3, required: true } },
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draWaterPrice',
                    title: '净水单价',
                    sortable: true,
                    // editor: {type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draBasicPrice',
                    title: '基准价',
                    // editor: {
                    //     type: 'numberbox',
                    //     options: {
                    //         precision: 3,
                    //         required: true
                    //     }
                    // },
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draDiffer',
                    title: '与基准价差额',
                    sortable: true,
                    // editor: {type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draDifferRadio',
                    title: '差额比例',
                    sortable: true,
                    // editor: {type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draMixPrice',
                    title: '单吨港杂费',
                    sortable: true,
                    /* editor: {type: 'numberbox', options: {precision: 3}},*/
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'draCommission',
                    title: '单吨佣金',
                    sortable: true,
                    editor: { type: 'numberbox', options: { precision: 3 } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'draTax',
                    title: '税率',
                    sortable: true,
                    //editor: {type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'draTaxNum',
                    title: '税码',
                    sortable: true,
                    /* editor: {
                          type: 'combobox',
                          options: {
                              url: 'sysDict/queryItemByTypeName?dicName=税码',
                              method: 'get',
                              valueField: "dicValue",
                              textField: "dicName",
                              editable: false,
                              required: true,
                          }
                      },*/
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'netWeight',
                    title: '产品净重',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'tare',
                    title: '皮重',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'draTotalPrice',
                    title: '原币价税合计',
                    sortable: true,
                    //  editor: {type: 'numberbox', options: {precision: 2}},
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draExeUnitPrice',
                    title: '原币无税单价',
                    sortable: true,
                    hidden: true,
                    editor: { type: 'numberbox', options: { precision: 3 } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                }, {
                    field: 'draDeliveryFactoryCode',
                    title: '交货工厂',
                    sortable: true,
                    hidden: true,
                    /* editor: {
                         type: 'combobox',
                         options: {
                             url: 'sysDict/queryItemByTypeName?dicName=交货工厂',
                             method: 'get',
                             valueField: "dicValue",
                             textField: "dicName",
                             editable: false,
                             required: true
                         }
                     },*/
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },

                {
                    field: 'remark',
                    title: '备注',
                    sortable: true,
                    hidden: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }];
            //合同类型为贸易时的列
            var tradeColumns = [
                {
                    field: 'draCostUnitPrice',
                    title: '成本单价',
                    sortable: true,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'proPoTransportUnitPrice',
                    title: '贸易运费单价',
                    sortable: true,
                    hidden: true,
                    editor: { type: 'numberbox', options: { required: false } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'purchaseAmount',
                    title: '采购数量',
                    sortable: true,
                    editor: { type: 'numberbox', options: { required: true, precision: 3 } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'purchasePrice',
                    title: '采购单价',
                    sortable: true,
                    editor: { type: 'numberbox', options: { required: true, precision: 3 } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                /*  {
                      field: 'purchasePrice',
                      title: '采购净水单价',
                      sortable: true,
                      hidden: true,
                      editor: {type: 'numberbox', options: {required: false}},
                      formatter: function (val, rec) {
                          return val ? unescape(val) : '';
                      }
                  },*/
                {
                    field: 'purchasePriceDiffer',
                    title: '销售单价差额',
                    sortable: true,
                    editor: { type: 'numberbox', options: { required: false, precision: 3 } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '0.000';
                    }
                },
                {
                    field: 'planArrivalDate',
                    title: '计划日期',
                    sortable: true,
                    editor: { type: 'datebox', options: { required: true } },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'arrivalFactory',
                    title: '到货工厂',
                    sortable: true,
                    editor: {
                        type: 'combobox',
                        options: {
                            url: 'sysDict/queryItemByTypeName?dicName=交货工厂',
                            method: 'get',
                            valueField: "dicValue",
                            textField: "dicName",
                            editable: false,
                            required: true,
                            onSelect: function (record) {
                                /* let proRow = $('#product').datagrid('getSelected')
                                 let rowIndex = $("#product").datagrid('getRowIndex', proRow);
                                 let arrivalFactoryTarget = $('#product').datagrid('getEditor', {
                                     index: rowIndex,
                                     field: 'arrivalFactory'
                                 }).target;
                                 let value = arrivalFactoryTarget.combobox('getValue');
                                 KCDD_URL = getRepertoryAddress(value)
                                 //此处field为第二个下拉列的field
                                 let appTarget = $('#product').datagrid('getEditor', {
                                     index: rowIndex,
                                     field: 'repertoryAddress'
                                 }).target;
                                 //清空
                                 appTarget.combobox('clear');
                                 appTarget.combobox('reload', KCDD_URL);*/
                            }
                        }
                    },
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                },
                {
                    field: 'repertoryAddress',
                    title: '库存地点',
                    sortable: true,
                    editor: {
                        type: 'combobox',
                        options: {
                            method: 'get',
                            valueField: "dicValue",
                            textField: "dicName",
                            editable: false,
                            required: true,
                            onSelect: function (record) {/*
                        let proRow = $('#product').datagrid('getSelected')
                        let rowIndex = $("#product").datagrid('getRowIndex', proRow);
                        let arrivalFactoryTarget = $('#product').datagrid('getEditor', {
                            index: rowIndex,
                            field: 'arrivalFactory'
                        }).target;
                        let value = arrivalFactoryTarget.combobox('getValue');
                        KCDD_URL = getRepertoryAddress(value)*/
                            },
                            onShowPanel: function () {
                                let proRow = $('#product').datagrid('getSelected')
                                let rowIndex = $("#product").datagrid('getRowIndex', proRow);
                                let arrivalFactoryTarget = $('#product').datagrid('getEditor', {
                                    index: rowIndex,
                                    field: 'arrivalFactory'
                                }).target;
                                let value = arrivalFactoryTarget.combobox('getValue');
                                KCDD_URL = getRepertoryAddress(value)
                                let appTarget = $('#product').datagrid('getEditor', {
                                    index: rowIndex,
                                    field: 'repertoryAddress'
                                }).target;
                                //清空
                                appTarget.combobox('clear');
                                appTarget.combobox('reload', KCDD_URL);
                            }

                        }

                    }

                    ,
                    formatter: function (val, rec) {
                        return val ? unescape(val) : '';
                    }
                }]
            var productModelsTemp = []

            // 行编辑结束
            function endEditing() {

                if (editIndex == undefined) {
                    return true
                }
                if ($('#product').datagrid('validateRow', editIndex)) {
                    $('#product').datagrid('endEdit', editIndex);
                    editIndex = undefined;
                    return true;
                } else {
                    $.messager.alert('提示', '有未填写数据!')
                    return false;
                }
            }

            // 根据合同金额的币种，计算汇率
            function setExchangeRate(record) {
                let fCURR = record.dicValue
                calculate(fCURR)

            }

            function calculate(fCURR) {
                let paramsZBS4 = {}
                paramsZBS4.ZBS = '4'
                paramsZBS4.FCURR = fCURR
                paramsZBS4.TCURR = 'CNY'
                paramsZBS4.GDATU = getNowFormatDate()
                // 取得汇率
                const exchangeRate = getDataFormSAP(paramsZBS4)
                $('#draRate').numberbox('setValue', JSON.parse(exchangeRate).UKURS)
            }

            /**
             * 计算汇率
             * 参数 FCURR（外币） TCURR（固定为CNY） GDATU（当前日期）
             */
            // 合同类型值改变时出发的方法
            function changeDisplay(rec) {
                if (rec.value == '1') {
                    // 贸易
                    // 将控件属性设为必填
                    $('#draCreateOrderFlag').combobox({ required: true })
                    $('#draCurrencyTrade').combobox({ required: true })
                    $('#draSupply').textbox({ required: true })
                    $('#draSettleFlag').combobox({ required: true })
                    $('#draWeighFlag').combobox({ required: true })
                    $('#draPackUp').combobox({ required: true })
                    $('#draPurchaseOrg').textbox({ required: true })
                    // 将采购组设置当前用户
                    $('#draPurchaseOrg').textbox('setValue', PUser.sap)
                    loadProductList([...productColumns, ...tradeColumns], productModelsTemp)
                    $('.draTypeFlag').css('display', 'table-row')

                } else {
                    $('#draCreateOrderFlag').combobox({ required: false })
                    $('#draCurrencyTrade').combobox({ required: false })
                    $('#draSupply').textbox({ required: false })
                    $('#draSettleFlag').combobox({ required: false })
                    $('#draWeighFlag').combobox({ required: false })
                    $('#draPackUp').combobox({ required: false })
                    $('#draPurchaseOrg').textbox({ required: false })
                    loadProductList(productColumns, productModelsTemp)
                    $('.draTypeFlag').css('display', 'none')
                }

            }

            /**
             * 根据是否进厂，初始化是否过磅的值
             */
            function changeWeighFlag(record) {
                let val = record.dicValue
                // 进厂
                if ('1' == val) {
                    $('#draWeighFlag').combobox('setValue', '2')
                } else {
                    $('#draWeighFlag').combobox('setValue', '1')
                }

            }


            // 根据交货工厂，获取库存地点的下拉数据
            function getRepertoryAddress(value) {
                return 'sysDict/queryItemByTypeName?dicName=' + value + '-贸易库存地点'
            }

            // tab未被选择的监听事件
            $('#tabs').tabs({
                onUnselect: function (title, index) {
                    if (endEditing()) {
                        $('#product').datagrid('acceptChanges');
                    }
                }

            })

            // 新增长约合同起草
            function addDraft() {
                $('#tabs').tabs({
                    tools: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            save('save');
                        }
                    }, {
                        text: '提交',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                function (r) {
                                    if (r) {
                                        save('submit')
                                    }
                                });
                        }
                    }]
                })
                $('#fm').form('clear');
                /*****某些字段初始化*******/
                // 合同签订日期设置为当前时间
                $('#draSignTime').datetimebox('setValue', myformatterDateTime(new Date()))
                // 清空合同产品列表
                loadProductList(productColumns, [])
                // 本页面均保存为长约合同
                $('#longTerm').combobox('setValue', '1')
                // 设置合同类型默认为非贸易
                $('#draTypeId').combobox('setValue', '0')
                // 设置包装费货币默认为CNY
                //   $('#draPackageCurrency').combobox('setValue', 'CNY')
                // 设置保险费货币默认为美元
                $('#draInsureCurrency').combobox('setValue', 'USD')
                // 设置销售凭证为默认值
                $('#draVouchaer').textbox('setValue', 'ZCQ1')
                // 设置 class=draTypeFlag 的css属性默认为不显示
                $('.draTypeFlag').css('display', 'none')

                $('#draChannelCode').combobox('setValue', '00')
                $('#draChannelCode').combobox('disable', 'true')


                selectedFileList = []
                $("#checkfileList").empty()
                // 打开新增窗口
                $('#add').window('open');
                $('#tabs').tabs('select', 0);
            }

            // 加载合同产品列表（履行明细）
            function loadProductList(columns, rows) {
                let pl = $('#product')
                pl.datagrid(
                    {
                        data: rows,
                        iconCls: 'icon-application',
                        clientPaging: false,
                        remoteFilter: true,
                        filterDelay: 0,
                        width: 830,
                        height: 300,
                        nowrap: true,
                        rownumbers: true,
                        animate: false,
                        collapsible: false,
                        singleSelect: true,
                        pageSize: 10,
                        remoteSort: false,
                        pagination: true,
                        columns: [columns],
                        onLoadSuccess: function () {
                        },
                        // 完成行编辑时的事件（结束当前行编辑后，开始下一行编辑前触发的）
                        onAfterEdit: function (rowIndex, rowData, changes) {


                        },
                        onEndEdit: function (index, row) {
                            /*var ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'draTaxNum'
                            });
                            row.draTax = $(ed.target).combobox('getText');*/
                            /*ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'draDeliveryFactoryCode'
                            });
                            row.draDeliveryFactoryName = $(ed.target).combobox('getText');*/

                            var ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'draPackageId'
                            });
                            row.draPackageName = $(ed.target).combobox('getText');

                            ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'arrivalFactory'
                            });
                            if (ed) {
                                row.arrivalFactoryName = $(ed.target).combobox('getText');
                            }

                            ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'repertoryAddress'
                            });

                            if (ed) {
                                row.repertoryAddressName = $(ed.target).combobox('getText');
                            }

                        },
                        onClickCell: function (rowIndex, field, value) {
                            if (editIndex != rowIndex) {
                                if (endEditing()) {

                                    $('#product').datagrid('selectRow', rowIndex)
                                        .datagrid('beginEdit', rowIndex);
                                    var ed = $('#product').datagrid('getEditor', { index: rowIndex, field: field });
                                    if (ed) {
                                        ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                                    }
                                    editIndex = rowIndex;
                                } else {
                                    setTimeout(function () {
                                        $('#dg').datagrid('selectRow', editIndex);
                                    }, 0);
                                }
                            }
                        }
                    }
                )
            }

            function querySkuVO(skuNum) {
                if (skuNum) {
                    $.ajax({
                        type: 'get',
                        url: 'sale/sku/master/selectInfor?skuNum=' + skuNum,
                        async: false,
                        success: function (data) {
                            if (data) {
                                return data.data
                            }
                        }
                    })
                }

            }

            // 销售组织change事件
            function changeElementByDraOrgCode(selected) {
                /**
                 * 区分内贸、外贸
                 */
                // in:内贸
                if (selected.remark == 'in') {
                    // 税率为13
                    $('#draTax').combobox('setValue', 'J6')
                    // 设置内陆运费总价货币为cny
                    $('#draTransportCurrency').combobox('setValue', 'CNY')
                    // 设置汇率为1
                    $('#draRate').numberbox('setValue', 1)
                    // 设置各字段币种
                    // 合同币种
                    $('#daCurrency').combobox('setValue', 'CNY')
                    //  海运费设置为非必填
                    $('#draSeaMoney').numberbox({ required: false })
                    // 海运费货币
                    $('#draSeaCurrency').combobox('setValue', 'CNY')
                    // 佣金货币
                    $('#draCommisionCurrency').combobox('setValue', 'CNY')
                    // 其余费用货币
                    $('#draOtherCurrency').combobox('setValue', 'CNY')
                    // 设置外贸术语未exw
                    $('#draTerminologyForeignTradeName').combobox('setValue', 'EXW')
                    $('#draTerminologyForeignTradeName').combobox('disable', 'true')
                } else {
                    // 税率为0
                    $('#draTax').combobox('setValue', 'J0')
                    // 设置各字段币种
                    // 合同币种
                    $('#daCurrency').combobox('setValue', 'USD')
                    // 计算汇率
                    calculate('USD')
                    // 设置内陆运费总价货币为cny
                    $('#draTransportCurrency').combobox('setValue', 'USD')
                    //  海运费设置为必填
                    $('#draSeaMoney').numberbox({ required: true })
                    // 海运费货币
                    $('#draSeaCurrency').combobox('setValue', 'USD')
                    // 佣金货币
                    $('#draCommisionCurrency').combobox('setValue', 'USD')
                    // 其余费用货币
                    $('#draOtherCurrency').combobox('setValue', 'USD')
                    // 设置外贸术语''
                    $('#draTerminologyForeignTradeName').combobox('setValue', '')
                    $('#draTerminologyForeignTradeName').combobox('enable', 'true')
                }
                // 根据销售组织，初始化待选sku物料列表
                let draOrgCodeTemp = selected.dicValue
                let draOrgNameTemp = selected.dicName
                let mmDataGrid = $('#mmDataGrid')
                mmDataGrid.datagrid('enableFilter');
                if (marketingOrganizingOfXY.indexOf(draOrgCodeTemp) !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '1000'
                    });
                } else if (marketingOrganizingOfSP.indexOf(draOrgCodeTemp) !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '1010'
                    });
                } else if (draOrgNameTemp.indexOf('欧洲') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '2010'
                    });
                } else if (draOrgNameTemp.indexOf('湖北新源') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '1020'
                    });
                } else if (draOrgNameTemp.indexOf('湖北浩科') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '1030'
                    });
                } else if (draOrgNameTemp.indexOf('新蔚源') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '1040'
                    });
                } else if (draOrgNameTemp.indexOf('上海宝山') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'product',
                        skuFactory: '2000'
                    });
                } else if (draOrgNameTemp.indexOf('采购销售组织') !== -1) {
                    mmDataGrid.datagrid('load', {
                        mMType: 'raw'
                        // skuFactory: '2010'
                    });
                }
            }


            // 条件查询
            function selectList() {
                var startTime = $('#startTime').datebox('getValue')
                var endTime = $('#endTime').datebox('getValue')
                var status = $('#status').combobox('getValue');
                var dg = $('#dg');
                dg.datagrid('enableFilter');
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    status: status ? status : '',
                    longTerm: '1'
                });
            }

            // 条件查询虚拟合同列表
            function selectVirtualList() {
                var startTime = $('#startTime').datebox('getValue')
                var endTime = $('#endTime').datebox('getValue')
                var dg = $('#dg');
                dg.datagrid('enableFilter');
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    status: '1',
                    draVirtual: '1'
                });
            }

            // 将选择的物资传给产品列表
            function addRowsToProduct() {
                const mMRows = $('#mmDataGrid').datagrid('getChecked')
                if (!mMRows) {
                    $('#selectMMWindow').window('close')
                    return
                }
                for (let i in mMRows) {
                    let mmTag = mMRows[i].mmTag
                    // 原料
                    if (mmTag == 'raw') {
                        let productItem = {
                            // sku编码
                            skuNum: mMRows[i].skuNum,
                            // sku描述
                            skuDescription: mMRows[i].skuDescription,
                            // 物料编码
                            draCode: mMRows[i].skuNum,
                            // 物料描述
                            draName: mMRows[i].skuDescription,
                            // 单位
                            draUnit: mMRows[i].skuUnit,
                            // 规格
                            draSpecs: mMRows[i].nedMmMain,
                            // 单个物料净重
                            draSkuMmTemp: mMRows[i].suttle,
                            // 单个sku物料净重
                            draSkuItemCount: mMRows[i].suttle,
                            // mmTag
                            mmTag: 'raw'
                        }

                        $('#product').datagrid('insertRow', { row: productItem })
                    } else {
                        // 产品
                        let skuNum = mMRows[i].skuNum
                        let skuFactory = mMRows[i].skuFactory
                        // 循环获取sku详情及行项目
                        $.ajax({
                            type: 'get',
                            url: 'sale/sku/master/selectInfor?skuNum=' + skuNum + '&skuFactory=' + skuFactory,
                            success: function (data) {
                                if (data.code != 60200) {
                                    $.messager.alert('消息', data.msg);
                                } else {
                                    // 获取SKU详情(包含SKU master与行项目)
                                    const result = data.data
                                    // 取出行项目
                                    const skuItems = result.skuItems
                                    if (null == skuItems || skuItems.length == 0) {
                                        $.messager.alert('提示', '未找到行项目')
                                        return
                                    }
                                    let skuItem = skuItems.find(function (item, index) {
                                        return item.itemType == 'N'
                                    })
                                    let productItem = {
                                        // sku编码
                                        skuNum: skuNum,
                                        // sku描述
                                        skuDescription: mMRows[i].skuDescription,
                                        // 物料编码
                                        draCode: skuItem.itemNum,
                                        // 物料描述
                                        draName: skuItem.itemDescription,
                                        // 单位
                                        draUnit: skuItem.itemUnit,
                                        // 规格
                                        draSpecs: mMRows[i].nedMmMain,
                                        // 单个物料净重
                                        draSkuMmTemp: mMRows[i].suttle,
                                        // 单个sku物料净重
                                        draSkuItemCount: skuItem.itemCount,
                                        // mmTag
                                        mmTag: 'product'

                                    }
                                    $('#product').datagrid('insertRow', { row: productItem })
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }

                        })
                    }

                }
                $('#selectMMWindow').window('close')
            }

            // 根据参数从sap抓取数据
            function getDataFormSAP(obj) {
                if (!obj) {
                    $.messager.alert('提示', '请求参数缺失')
                    return
                }
                let result = null;
                $.ajax({
                    type: 'post',
                    url: 'sale/contract/draft/getDataFormSAPByParams',
                    data: JSON.stringify(obj),
                    dataType: 'json',
                    contentType: "application/json",
                    async: false,
                    success: function (data) {
                        if (data.code == '60200') {
                            result = data.data
                        } else {
                            let msgStr = ''
                            if (obj.ZBS == '1') {
                                msgStr = '运费'
                            } else if (obj.ZBS == '2') {
                                msgStr = '包装费'
                            } else if (obj.ZBS == '3') {
                                msgStr = '基准价'
                            } else if (obj.ZBS == '4') {
                                msgStr = '汇率'
                            }
                            $.messager.show({
                                title: 'SAP接口回执',
                                msg: '未在SAP系统中查询到' + msgStr,
                                timeout: 3000,
                                showType: 'show'
                            });
                        }
                    }
                })
                return result
            }

            // 移除产品明细
            function removeProduct() {
                let row = $('#product').datagrid('getSelected')
                if (!row) {
                    $.messager.alert('提示', '请选择要移除的数据。')
                    return
                }
                // 获取索引
                let index = $('#product').datagrid('getRowIndex', row)
                // 删除前结束编辑
                $('#product').datagrid('endEdit', editIndex);
                editIndex = undefined;
                // 删除行
                $('#product').datagrid('deleteRow', index)

            }

            function del(node) {
                $.ajax({
                    type: "delete",
                    url: 'sale/contract/draft/delete?id=' + node.draId,
                    //                dataType: "xml",
                    success: function (data) {
                        $.messager.alert('消息', data.msg);
                        let dg = $('#dg');
                        dg.datagrid('enableFilter');
                        dg.datagrid('load');
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            // 保存
            function save(action) {
                if (!endEditing()) {
                    $.messager.alert('提示', '行编辑未结束')
                    return;
                }

                if (!$('#draProceedsName').combobox('getValue')) {
                    $.messager.alert('提示', '收款条件不存在，请联系管理员。');
                    return
                }
                if ('1' == $('#draTypeId').combobox('getValue')) {
                    if (!$('#draPaymentName').combobox('getValue')) {
                        $.messager.alert('提示', '付款条件不存在，请联系管理员。');
                        return
                    }
                }
                if ($('#draStartTime').datebox('getValue') >= $('#draEndTime').datebox('getValue')) {
                    $.messager.alert('提示', '合同开始日期不得大于截至日期');
                    return
                }
                // 合同金额货币
                let currencyTemp = $('#daCurrency').combobox('getValue')
                let currencyTextTemp = $('#daCurrency').combobox('getText')
                // 汇率
                let draRateTem = $('#draRate').numberbox('getValue')
                if (!draRateTem) {
                    $.messager.alert('警告', '请输入汇率')
                    return
                }
                // 海运费
                let SeaMoneyTemp = $('#draSeaMoney').numberbox('getValue') ? $('#draSeaMoney').numberbox('getValue') : 0
                // 其余费用
                let otherMoneyTemp = $('#draOtherMoney').numberbox('getValue') ? $('#draOtherMoney').numberbox('getValue') : 0
                // 计算保险费
                let insureMoneyTemp = 0
                if ($('#draOrgCode').combobox('getText').indexOf("国外") != -1) {
                    let draTerminologyForeignTradeNameTemp = $('#draTerminologyForeignTradeName').combobox('getValue')
                    // 保险费的缺省值
                    let defaultInsureMoney = (50 / draRateTem).toFixed(2)
                    if (draTerminologyForeignTradeNameTemp == 'CIF' || draTerminologyForeignTradeNameTemp == 'DDP') {
                        // 外贸:计算保险费：（合同美金总额*1.1*1.98）/10000
                        // 合同美金总额
                        let contractMoneies = $('#draMoney').numberbox('getValue') ? Number($('#draMoney').numberbox('getValue')) : 0
                        insureMoneyTemp = (contractMoneies * 1.1 * 1.98) / 10000
                        // 当计算出来的保险费<50CNY时，按50CNY赋值
                        if (insureMoneyTemp == 0 || insureMoneyTemp < defaultInsureMoney) {
                            insureMoneyTemp = defaultInsureMoney
                        }
                        Number(insureMoneyTemp).toFixed(2)
                        $('#draInsureMoney').numberbox('setValue', insureMoneyTemp)
                    } else {
                        $('#draInsureMoney').numberbox('setValue', 0)
                    }
                } else {
                    $('#draInsureMoney').numberbox('setValue', 0)
                }
                $('#product').datagrid('acceptChanges');
                if (!$('#fm').form('validate')) {
                    $.messager.alert('提示', '有必填项未填写')
                    return;
                }
                // 包装费合计
                let packageMoneies = $('#draPackageMoney').numberbox('getValue');
                //  佣金合计
                let draCommisionTotal = 0;

                // 获取产品列表
                let products = $('#product').datagrid('getRows')
                // 内陆运输总价计算
                let transportTotlPrice = $('#draTransportMoney').numberbox('getValue');
                // 循环获取合同所有产品的总吨数（数量*物料净重）;设置包装费货币为合同金额货币
                let productsTotalWeight = 0
                // 获取运输方式
                let transportModeCode = $('#draTransportName').combobox('getValue')

                for (let i in products) {
                    // 将产品id置空
                    products[i].proId = ''

                    // 贸易时，采购单价不得大于原币含税单价
                    if ('1' == $('#draTypeId').combobox('getValue')) {
                        let purchasePrice = products[i].purchasePrice ? (Number(products[i].purchasePrice) / draRateTem).toFixed(3) : 0
                        let draUnitPrice = products[i].draUnitPrice ? Number(products[i].draUnitPrice) : 0
                        if (purchasePrice > draUnitPrice) {
                            $.messager.alert('提示', '采购单价不得大于原币含税单价')
                            return;
                        }
                    }

                    // 产品的单吨佣金
                    // let productUnitTOCommision = products[i].draCommission ? Number(products[i].draCommission) : 0;
                    // 设置包装费货币为合同金额货币
                    products[i].draPackageCurrency = currencyTemp
                    products[i].draPackageCurrencyName = currencyTextTemp
                    // 数量
                    let draNum = products[i].draNum ? Number(products[i].draNum) : 0
                    // 如果mm为产品，走sku计算路线
                    if (products[i].mmTag == 'product') {
                        // 单个skuitem的物料净重（比例）
                        let draSkuItemCountTemp = products[i].draSkuItemCount ? Number(products[i].draSkuItemCount) : 0
                        // 单个skuitem的物料净重*数量 = 吨数
                        let draSkuItemCount = Number(draNum * draSkuItemCountTemp)
                        // 如果运输方式为汽运-电子级槽车、汽运-工业级槽车，吨数小于29吨时，按29吨算
                        if ('Z0050' == transportModeCode || 'Z0060' == transportModeCode) {
                            draSkuItemCount = draSkuItemCount <= 29 ? 29 : draSkuItemCount
                        }
                        if ('Z0070' == transportModeCode) {
                            draSkuItemCount = draSkuItemCount <= 28 ? 28 : draSkuItemCount
                        }
                        productsTotalWeight += draSkuItemCount
                        // 佣金合计= 产品吨数*单吨佣金
                        //  draCommisionTotal += productUnitTOCommision * draSkuItemCount
                    } else {
                        productsTotalWeight += draNum
                        // draCommisionTotal += productUnitTOCommision
                    }
                    // 设置佣金总金额
                    //  $('#draCommisionMoney').numberbox('setValue', draCommisionTotal)
                }

                /**
                 *产品字段计算与赋值
                 */

                for (let i in products) {
                    let mmTag = products[i].mmTag
                    // SKU编码
                    let skuNum = products[i].skuNum
                    // 产品编码
                    let mmCode = products[i].draCode
                    let draNum = products[i].draNum ? Number(products[i].draNum) : 0
                    // 计算每行产品的单吨港杂费（港杂费总额/所有合同总吨数）
                    /* if (!otherMoneyTemp || otherMoneyTemp == 0) {
                         products[i].draMixPrice = 0
                     } else {
                         products[i].draMixPrice = (Number(otherMoneyTemp) / Number(productsTotalWeight)).toFixed(3)
                     }*/

                    // 原币含税单价
                    let draUnitPriceTemp = products[i].draUnitPrice ? Number(products[i].draUnitPrice) : 0
                    /**
                     * 字段赋值
                     * */
                    // 基本信息的税码税率，赋值产品列表的
                    products[i].draTax = $('#draTax').combobox('getText')
                    products[i].draTaxNum = $('#draTax').combobox('getValue')


                    // 根据基本信息得销售组织选项，默认产品的交货工厂值
                    let draOrgTem = $('#draOrgCode').combobox('getText')
                    if (draOrgTem.indexOf('海科新源') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[0].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[0].label
                    } else if (draOrgTem.indexOf('欧洲') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[2].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[2].label

                    } else if (draOrgTem.indexOf('江苏思派') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[1].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[1].label
                    } else if (draOrgTem.indexOf('湖北材料') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[3].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[3].label
                    } else if (draOrgTem.indexOf('湖北浩科') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[4].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[4].label
                    } else if (draOrgTem.indexOf('新蔚源') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[5].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[5].label
                    } else if (draOrgTem.indexOf('上海宝山') != -1) {
                        products[i].draDeliveryFactoryCode = draDeliveryFactoryEnum[6].code
                        products[i].draDeliveryFactoryName = draDeliveryFactoryEnum[6].label
                    }

                    // 单个skuitem的物料净重（比例）
                    let draSkuItemCountTemp = products[i].draSkuItemCount ? Number(products[i].draSkuItemCount) : 0
                    // 发货工厂：根据销售组织判断
                    let draOrgCode = $('#draOrgCode').combobox('getText')
                    let wERKS = ""
                    if (draOrgCode.indexOf('海科新源') != -1) {
                        wERKS = '1000'
                    } else if (draOrgCode.indexOf('江苏思派') != -1) {
                        wERKS = '1010'
                    } else if (draOrgCode.indexOf('欧洲') != -1) {
                        wERKS = '2010'
                    } else if (draOrgCode.indexOf('湖北材料') != -1) {
                        wERKS = '1020'
                    } else if (draOrgCode.indexOf('湖北浩科') != -1) {
                        wERKS = '1030'
                    } else if (draOrgCode.indexOf('新蔚源') != -1) {
                        wERKS = '1040'
                    } else if (draOrgCode.indexOf('上海宝山') != -1) {
                        wERKS = '2000'
                    }
                    if ('product' == mmTag) {
                        // 计算运费ZBS = '1'：所需参数：发货工厂、目的地代码、物料编码、数量
                        //   let paramsZBS1 = {}
                        //   paramsZBS1.ZBS = '1'
                        //   paramsZBS1.WERKS = wERKS
                        // 到货地址
                        // paramsZBS1.ZMDD = $('#draAddress').combobox('getValue')
                        // 运输方式
                        //  paramsZBS1.YSFS = $('#draTransportName').combobox('getValue')

                        // 物料数量
                        //   paramsZBS1.KWMENG = draNum
                        // 物料编码
                        //   paramsZBS1.MATNR = skuNum.replace(/(^\s*)|(\s*$)/g, "")
                        // 取得运费单价
                        // let transportPrice = getDataFormSAP(paramsZBS1)
                        // 贸易时，且供应商送货，运费为0
                        // if ('1' == $('#draTypeId').combobox('getValue') && '2' == $('#draPackUp').combobox('getValue')) {
                        //products[i].transportPrice = 0
                        //  } else if ('Z0230' == transportModeCode || 'Z0240' == transportModeCode) {
                        //      products[i].transportPrice = 0
                        //  }else {
                        // if (transportPrice) {
                        // 设置运费单价
                        // 货币为CNY时，不除税率
                        /*if ('CNY' == $('#daCurrency').combobox('getValue')) {
                            if ($('#draTax').combobox('getValue') == 'J0') {
                                products[i].transportPrice = Number(JSON.parse(transportPrice).ZDDJE1 / draRateTem / 1.13)
                            } else {
                                products[i].transportPrice = Number(JSON.parse(transportPrice).ZDDJE1 / draRateTem)
                            }
        
                        } else {
                            products[i].transportPrice = Number(JSON.parse(transportPrice).ZDDJE1 / draRateTem / 1.13)
                        }*/
                        /* // 若产品为丁二醇、戊二醇、已二醇时，单吨运费+50CNY
                         if (products[i].draName.indexOf('丁二醇') !== -1 || products[i].draName.indexOf('戊二醇') !== -1 || products[i].draName.indexOf('已二醇') !== -1) {
                             products[i].transportPrice = Number(products[i].transportPrice) + Number(50)
                         }*/
                        // }
                        //  }
                        // 内陆运输总价汇总
                        //当运输方式为Z0010时，sku数量除以120，向上取整
                        let draNumTmp = draNum
                        // if ('Z0010' == transportModeCode) {
                        //     draNumTmp = Math.ceil(draNum / 120)
                        //  }
                        //当运输方式为Z0020时，sku数量除以80，向上取整
                        //  else if ('Z0020' == transportModeCode) {
                        //     draNumTmp = Math.ceil(draNum / 80)
                        // }
                        // 单个skuitem的物料净重*数量 = 吨数
                        // let draSkuItemTonCount = draNumTmp * draSkuItemCountTemp
                        // 如果运输方式为汽运-电子级槽车、汽运-工业级槽车，吨数小于29吨时，按29吨算
                        /*if ('Z0050' == transportModeCode || 'Z0060' == transportModeCode) {
                            draSkuItemTonCount = draSkuItemTonCount <= 29 ? 29 : draSkuItemTonCount
                        }
                        if ('Z0070' == transportModeCode) {
                            draSkuItemTonCount = draSkuItemTonCount <= 28 ? 28 : draSkuItemTonCount
                        } else {
                            draSkuItemTonCount = draSkuItemTonCount <= 1 ? 1 : draSkuItemTonCount
                        }*/
                        /**   1.运输方式50、60小于等于29吨，按29吨算；
                         2.70小于等于28吨，按28吨；
                         3.10 sku个数除120，向上取整；20 sku个数除80，向上取证；
                         4.30、40按照sku个数；*/
                        //当运输方式为Z0030、Z0040时，总运费=（运费单价*sku数量）之和
                        /* if ('Z0010' == transportModeCode || 'Z0020' == transportModeCode || 'Z0030' == transportModeCode || 'Z0040' == transportModeCode) {
                             transportTotlPrice += products[i].transportPrice * draNumTmp
                         } else {
                             transportTotlPrice += products[i].transportPrice * draSkuItemTonCount
                         }*/


                        /**
                         * 计算包装费
                         * 参数 ZBS（标识）、MATNR（SKU编码）、WERKS（发货工厂）、BZFS（包装方式）、ERDAT1（传输时期）
                         */
                        // 贸易时且供应商送货时，包装费为0
                        if ('1' == $('#draTypeId').combobox('getValue') && '2' == $('#draPackUp').combobox('getValue')) {
                            products[i].draPackExpense = 0
                        } else if ('Z0230' == transportModeCode) {
                            // 运输方式为自提时，总包装费为0
                            products[i].draPackExpense = 0
                        }  /*else {
                   let paramsZBS2 = {}
                    paramsZBS2.ZBS = '2'
                    paramsZBS2.MATNR = skuNum
                    paramsZBS2.WERKS = wERKS
                    let packageType = products[i].draPackageId ? products[i].draPackageId : ''
                    paramsZBS2.BZFS = packageType
                    paramsZBS2.KWMENG = draNum
                    paramsZBS2.ERDAT1 = getNowFormatDate()*/

                        // 取得包装费单价
                        // let packagePrice = getDataFormSAP(paramsZBS2)
                        //  设置包装费
                        /* if (packagePrice) {
                             // 包装费
                             let packageUnitPrice = JSON.parse(packagePrice).ZDDJE2 ? Number(JSON.parse(packagePrice).ZDDJE2) : 0
                             // 需转换汇率
                             if (draSkuItemCountTemp == 0) {
                                 products[i].draPackExpense = 0
                             } else {
                                 // 此处返回的是总sku的包装费
                                 if ('CNY' == $('#daCurrency').combobox('getValue')) {
                                     if ($('#draTax').combobox('getValue') == 'J0') {
                                         products[i].draPackExpense = (packageUnitPrice / draRateTem / 1.13)
                                     } else {
                                         products[i].draPackExpense = (packageUnitPrice / draRateTem)
                                     }
        
                                 } else {
                                     products[i].draPackExpense = (packageUnitPrice / draRateTem / 1.13)
                                 }
                             }
                         } else {
                             products[i].draPackExpense = 0
                         }
                     }*/

                        // 包装数量
                        // products[i].draPackageNum = draNum


                        /**
                         * 计算基准价
                         * 参数 ZBS（标识）、MATNR（SKU编码）、WERKS（发货工厂）KUNNR（客户）VKORG（销售组织）BZIRK（销售地区）COUNTRY（国家）
                         * KUKLA（客户级别）ERDAT2（日期）
                         */
                        let paramsZBS3 = {}
                        paramsZBS3.ZBS = '3'
                        paramsZBS3.MATNR = skuNum
                        paramsZBS3.WERKS = wERKS
                        // 合同币种
                        paramsZBS3.ZHB1 = $('#daCurrency').combobox('getValue') ? $('#daCurrency').combobox('getValue') : ''
                        // 结算方式
                        paramsZBS3.JSFS = $('#draSettleName').combobox('getValue') ? $('#draSettleName').combobox('getValue') : ''
                        //paramsZBS3.KUNNR = $('#infCode').val()
                        // 销售组织
                        paramsZBS3.VKORG = $('#draOrgCode').combobox('getValue')
                        //   paramsZBS3.COUNTRY = $('#infCountry').textbox('getValue')
                        // 客户分类
                        paramsZBS3.KUKLA = $('#classificationDescr').combobox('getValue')
                        // 当前日期
                        paramsZBS3.ERDAT2 = getNowFormatDate()
                        // 设置基准价
                        // 贸易时，基准价为0
                        if ('1' == $('#draTypeId').combobox('getValue')) {
                            products[i].draBasicPrice = 0
                        } else {
                            // 判断产品是否需要获取远期基准价
                            let result = queryProductCodeWhetherNeedGetForward(mmCode)
                            // 需要获取远期基准价
                            if (result) {
                                // 计划完成发货日期
                                let planCompleteDeliveryDate = $('#draPlanCompleteDeliveryTime').datetimebox('getValue')
                                if (!planCompleteDeliveryDate) {
                                    $.messager.alert('提示', '请选择计划完成发货日期。')
                                    return
                                }

                                paramsZBS3.ERDAT2 = planCompleteDeliveryDate.substr(0, 10)
                            } else {
                                // 非远期定价，将计划完成发货日期置空
                                $('#draPlanCompleteDeliveryTime').datetimebox('setValue', '')
                            }
                            // 取得基准价
                            let basicPrice = getDataFormSAP(paramsZBS3)
                            if (basicPrice) {
                                products[i].draBasicPrice = (JSON.parse(basicPrice).ZJZJ ? Number(JSON.parse(basicPrice).ZJZJ) : 0)
                            } else {
                                products[i].draBasicPrice = 0
                            }
                        }


                        // 计算每个sku产品的原币无税单价
                        let draTaxTem = Number(products[i].draTax) / 100
                        products[i].draExeUnitPrice = draUnitPriceTemp / (Number(1) + Number(draTaxTem))
                    } else {
                        //  transportTotlPrice = 0
                        //  products[i].draPackExpense = 0
                        //  products[i].draPackageNum = 0
                        // 设置基准价
                        //   products[i].draBasicPrice = 0
                    }


                }
                // 如果销售贸易且为供应商送货，则总运输价为0
                /* if ('1' == $('#draTypeId').combobox('getValue') && '2' == $('#draPackUp').combobox('getValue')) {
                     transportTotlPrice = 0
        
                 }*/

                // 如果销售贸易且为自提，则总运输价为运输总成本
                if ('1' == $('#draTypeId').combobox('getValue') && '1' == $('#draPackUp').combobox('getValue')) {
                    if ('CNY' == currencyTemp) {
                        transportTotlPrice = $('#draTransportTotalCost').numberbox('getValue') ? Number($('#draTransportTotalCost').numberbox('getValue')) / draRateTem : transportTotlPrice
                    } else {
                        transportTotlPrice = $('#draTransportTotalCost').numberbox('getValue') ? Number($('#draTransportTotalCost').numberbox('getValue')) / draRateTem / 1.13 : transportTotlPrice
                    }
                    // 设置内陆运输总价
                    $('#draTransportMoney').numberbox('setValue', Number(transportTotlPrice))

                }


                // 计算每行净水价
                let commisionMoneyTmp = $('#draCommisionMoney').numberbox('getValue')
                commisionMoneyTmp = commisionMoneyTmp ? Number(commisionMoneyTmp) : Number(0)
                for (let i in products) {
                    let mmTag = products[i].mmTag
                    // 净水价Temp
                    let draWaterPriceTemp = 0
                    // 基准价
                    let draBasicPriceTemp = products[i].draBasicPrice
                    let draNum = products[i].draNum ? Number(products[i].draNum) : 0
                    // 单个sku物料的净重
                    let draSkuItemCountTemp = products[i].draSkuItemCount ? products[i].draSkuItemCount : 0
                    // 原币含税单价
                    let draUnitPriceTemp = products[i].draUnitPrice ? Number(products[i].draUnitPrice) : 0
                    if ('product' == mmTag) {
                        // 产品净重
                        let netWeightTmp = Number(draSkuItemCountTemp) * draNum
                        products[i].netWeight = netWeightTmp
                        products[i].draTotalPrice = draUnitPriceTemp * netWeightTmp
                        // 净水价计算（单产品总金额/单产品吨数）-（（佣金+保险费+海运费+内陆运费总额+杂费+包装费）/多产品总吨数）
                        let cbUnitPrice = ((Number(commisionMoneyTmp) + Number(insureMoneyTemp) + Number(SeaMoneyTemp) + Number(packageMoneies) + Number(otherMoneyTemp)) / Number(productsTotalWeight)).toFixed(3)
                        // 内陆运费总额/多产品总吨数
                        let oneUnitTransportPrice = Number(transportTotlPrice) / Number(productsTotalWeight)
                        draWaterPriceTemp = Number(draUnitPriceTemp) - (cbUnitPrice ? Number(cbUnitPrice).toFixed(3) : 0) - Number(oneUnitTransportPrice)

                    } else {
                        products[i].netWeight = draNum
                        products[i].draTotalPrice = draUnitPriceTemp * draNum
                        draWaterPriceTemp = draUnitPriceTemp
                    }
                    // 求实际单吨运费
                    /*if (products[i].transportPrice) {
                        products[i].realUnitTransportMonry = products[i].netWeight <= 1 ? (Number(products[i].transportPrice) / Number(products[i].netWeight)).toFixed(3) : products[i].transportPrice
                    } else {
                        products[i].realUnitTransportMonry = 0.000
                    }*/
                    //净水价赋值
                    products[i].draWaterPrice = draWaterPriceTemp
                    // 与基准价差额
                    products[i].draDiffer = products[i].draBasicPrice - draWaterPriceTemp
                    // 差额比例（与基准价差额/基准价）
                    products[i].draDifferRadio = draBasicPriceTemp == 0 ? 0 : (products[i].draDiffer / draBasicPriceTemp)

                    // 计算成本单价(合同类型==1)
                    if ('1' == $('#draTypeId').combobox('getValue')) {
                        let draPurchaseTotalCounttemp = $('#draPurchaseTotalCount').numberbox('getValue') ? $('#draPurchaseTotalCount').numberbox('getValue') : 0
                        products[i].draCostUnitPrice = (Number(packageMoneies) + Number(transportTotlPrice)) / draPurchaseTotalCounttemp
                    }

                }

                var model = {
                    productModels: products,
                    draId: $('#draId').val(),
                    draCode: $('#draCode').val(),
                    oldDraId: $('#oldDraId').val(),
                    oldDraCode: $('#oldDraCode').textbox('getValue'),
                    draVirtual: '0',

                    draName: $('#draName').val(),
                    draMoney: $('#draMoney').numberbox('getValue'),
                    draTaxId: $('#draTax').combobox('getValue'),
                    draTax: $('#draTax').combobox('getText'),
                    draTransportId: $('#draTransportName').combobox('getValue'),
                    draTransportName: $('#draTransportName').combobox('getText'),
                    // draIsIn: $('#draIsIn').combobox('getValue'),
                    draSettleId: $('#draSettleName').combobox('getValue'),
                    draSettleName: $('#draSettleName').combobox('getText'),
                    // 包装费
                    draPackageMoney: $('#draPackageMoney').numberbox('getValue'),
                    draTransportMoney: $('#draTransportMoney').numberbox('getValue'),
                    draTransportCurrency: $('#draTransportCurrency').combobox('getValue'),
                    // draDays: $('#draDays').val(),
                    draPaymentId: $('#draPaymentName').combobox('getValue'),
                    draPaymentName: $('#draPaymentName').combobox('getText'),
                    infCode: $('#infCode').val(),
                    infName: $('#infName').textbox('getValue'),
                    infCountry: $('#infCountry').textbox('getValue'),
                    infTel: $('#infTel').numberbox('getValue'),
                    infLegalPerson: $('#infLegalPerson').val(),
                    infHandlePerson: $('#infHandlePerson').val(),
                    draTypeId: $('#draTypeId').combobox('getValue'),
                    longTerm: '1',
                    draTypeName: $('#draTypeId').combobox('getText'),
                    draSignTime: $('#draSignTime').datetimebox('getValue'),
                    draStartTime: $('#draStartTime').datetimebox('getValue'),
                    draEndTime: $('#draEndTime').datetimebox('getValue'),
                    oaUserId: $('#oaUserId').val(),
                    oaWfId: $('#oaWfId').val(),
                    daCurrency: $('#daCurrency').combobox('getValue'),
                    draSeaMoney: $('#draSeaMoney').numberbox('getValue'),
                    draRate: $('#draRate').numberbox('getValue'),
                    /* draAgreementId: $('#draAgreementId').val(),
                     draAgreementName: $('#draAgreementName').val(),*/
                    draVouchaer: $('#draVouchaer').textbox('getValue'),
                    draOrgCode: $('#draOrgCode').combobox('getValue'),
                    draChannelCode: $('#draChannelCode').combobox('getValue'),
                    draChannelName: $('#draChannelCode').combobox('getText'),
                    draGroup: $('#draGroup').combobox('getValue'),
                    draGroupName: $('#draGroup').combobox('getText'),
                    //draInvoice: $('#draInvoice').val(),
                    //draBillNum: $('#draBillNum').val(),
                    //draBillNum: $('#draBillNum').val(),
                    draAddress: $('#draAddress').combogrid('getValue'),
                    draAddressName: $('#draAddress').combogrid('getText'),
                    draAddressDetail: $('#draAddressDetail').textbox('getValue'),
                    //  draPackageCode: $('#draPackageCode').combobox('getValue'),
                    draPackageName: $('#draGroup').combobox('getValue'),
                    // draPackageNum: $('#draPackageNum').numberbox('getValue'),
                    // draOrderRemark: $('#draOrderRemark').val(),
                    // draGoodsRemark: $('#draGoodsRemark').val(),
                    draOtherMoney: $('#draOtherMoney').numberbox('getValue'),
                    draOtherCurrency: $('#draOtherCurrency').combobox('getValue'),
                    // draPackageCurrency: $('#draPackageCurrency').combobox('getValue'),
                    draInsureMoney: $('#draInsureMoney').numberbox('getValue'),
                    draCommisionMoney: $('#draCommisionMoney').numberbox('getValue'),
                    draCommisionCurrency: $('#draCommisionCurrency').combobox('getValue'),
                    draSeaCurrency: $('#draSeaCurrency').combobox('getValue'),
                    draInsureCurrency: $('#draInsureCurrency').combobox('getValue'),
                    draSaleAreaCode: $('#draSaleAreaCode').combobox('getValue'),
                    draSaleAreaName: $('#draSaleAreaCode').combobox('getText'),
                    draIsPlanAccounting: $('#draIsPlanAccounting').combobox('getValue'),
                    status: '0',
                    draCreateOrderFlag: $('#draCreateOrderFlag').combobox('getValue'),
                    draCurrencyTrade: $('#draCurrencyTrade').combobox('getValue'),
                    draPurchaseOrg: $('#draPurchaseOrg').textbox('getValue'),
                    draSupply: $('#draSupply').textbox('getValue'),
                    draSupplyCode: $('#draSupplyId').val(),
                    draSettleFlag: $('#draSettleFlag').combobox('getValue'),
                    draWeighFlag: $('#draWeighFlag').combobox('getValue'),
                    draPackUp: $('#draPackUp').combobox('getValue'),
                    draProceedsCode: $('#draProceedsName').combobox('getValue'),
                    draProceedsName: $('#draProceedsName').combobox('getText'),
                    draTerminologyForeignTradeName: $('#draTerminologyForeignTradeName').combobox('getText'),
                    draTerminologyForeignTradeCode: $('#draTerminologyForeignTradeName').combobox('getValue'),
                    // draPackageTotalCost: $('#draPackAgeTotalCost').numberbox('getValue'),
                    draTransportTotalCost: $('#draTransportTotalCost').numberbox('getValue'),
                    draPurchaseTotalAmount: $('#draPurchaseTotalAmount').numberbox('getValue'),
                    draPurchaseTotalCount: $('#draPurchaseTotalCount').numberbox('getValue'),
                    classification: $('#classificationDescr').combobox('getValue'),
                    classificationDescr: $('#classificationDescr').combobox('getText'),
                    draPlanCompleteDeliveryTime: $('#draPlanCompleteDeliveryTime').datetimebox('getValue')
                };
                saveAjax(model, action)
            }

            // 保存的ajax
            function saveAjax(obj, action) {
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: 'sale/contract/draft/save',
                    data: JSON.stringify(obj),
                    contentType: "application/json",
                    success: function (data) {
                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.responseJSON.code != 60200) {
                            $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                        } else {
                            const result = XMLHttpRequest.responseJSON.data
                            $('#draCode').val(result.draCode)
                            obj.draCode = result.draCode
                            saveAttch(result.draId, obj, action)
                            if ('submit' != action) {
                                $.messager.show({
                                    title: '提示',
                                    msg: XMLHttpRequest.responseJSON.msg,
                                    timeout: 3000,
                                    showType: 'slide'
                                });
                                let dg = $('#dg');
                                dg.datagrid('enableFilter');
                                dg.datagrid('load');
                                $('#add').window('close');
                                // 重新打开窗口
                                if ('1' != result.status) {
                                    $('#tabs').tabs({
                                        tools: [{
                                            text: '保存',
                                            iconCls: 'icon-save',
                                            handler: function () {
                                                save('save');
                                            }
                                        }, {
                                            text: '提交',
                                            iconCls: 'icon-ok',
                                            handler: function () {
                                                $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                    function (r) {
                                                        if (r) {
                                                            save('submit')
                                                        }
                                                    });
                                            }
                                        }]
                                    })
                                } else {
                                    $('#tabs').tabs({
                                        tools: null
                                    })
                                }
                                ajaxGetDetailByDraId(result.draId, 'detail')
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        disLoad();
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            // 根据id 获取详情的ajax
            function ajaxGetDetailByDraId(draId, action) {
                $.ajax({
                    type: "get",
                    dataType: "json",
                    url: 'sale/contract/draft/selectInfor?id=' + draId,
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', data.msg);
                        } else {
                            let row = data.data
                            // 根据销售组织，设置海运费是否必填
                            // 属于内贸
                            if (marketingOrganizingIn.includes(row.draOrgCode)) {
                                $('#draSeaMoney').numberbox({ required: false })
                            } else {
                                $('#draSeaMoney').numberbox({ required: true })
                            }
                            // 根据合同类型是否是贸易，设置贸易字段类是否显示
                            let draTypeId = row.draTypeId
                            draTypeId == '1' ? $('.draTypeFlag').css('display', 'table-row') : $('.draTypeFlag').css('display', 'none')
                            if ('detail' == action) {
                                $('#draId').val(draId)// 长约合同id
                                $('#draCode').val(row.draCode)// 长约合同编号
                                $('#oldDraId').val(row.oldDraId)// 原虚拟合同id
                                $('#oldDraCode').textbox('setValue', row.oldDraCode)// 原虚拟合同编号
                            } else {
                                $('#draId').val('')// 长约合同id
                                $('#draCode').val('')// 长约合同编号
                                $('#oldDraId').val(draId)// 原虚拟合同id
                                $('#oldDraCode').textbox('setValue', row.draCode)// 原虚拟合同编号
                            }
                            $('#draName').val(row.draName)
                            $('#draMoney').numberbox('setValue', row.draMoney)
                            $('#draTax').combobox('setValue', row.draTaxId)
                            $('#draTransportName').combobox('setValue', row.draTransportId)
                            $('#draSettleName').combobox('setValue', row.draSettleId)
                            // 包装费
                            $('#draPackageMoney').numberbox('setValue', row.draPackageMoney)
                            $('#draTransportMoney').numberbox('setValue', row.draTransportMoney)
                            $('#draTransportCurrency').combobox('setValue', row.draTransportCurrency)

                            $('#infCode').val(row.infCode)
                            $('#infName').textbox('setValue', row.infName)
                            $('#infTel').numberbox('setValue', row.infTel), $('#infLegalPerson').val(row.infLegalPerson)
                            $('#infHandlePerson').val(row.infHandlePerson)
                            $('#infCountry').textbox('setValue', row.infCountry)
                            $('#draTypeId').combobox('setValue', row.draTypeId)
                            $('#longTerm').combobox('setValue', '1')
                            $('#draSignTime').datetimebox('setValue', row.draSignTime)
                            $('#draStartTime').datetimebox('setValue', row.draStartTime)
                            $('#draEndTime').datetimebox('setValue', row.draEndTime)
                            $('#oaUserId').val(row.oaUserId)
                            $('#oaWfId').val(row.oaWfId)
                            $('#daCurrency').combobox('setValue', row.daCurrency)
                            $('#draSeaMoney').numberbox('setValue', row.draSeaMoney)
                            $('#draRate').numberbox('setValue', row.draRate)

                            $('#draVouchaer').textbox('setValue', row.draVouchaer)
                            $('#draOrgCode').combobox('setValue', row.draOrgCode)
                            $('#draChannelCode').combobox('setValue', row.draChannelCode)
                            $('#draGroup').combobox('setValue', row.draGroup)

                            $('#draAddress').combogrid('setValue', row.draAddress)
                            $('#draAddressDetail').textbox('setValue', row.draAddressDetail)

                            $('#draOtherMoney').numberbox('setValue', row.draOtherMoney)
                            $('#draOtherCurrency').combobox('setValue', row.draOtherCurrency)
                            $('#draInsureMoney').numberbox('setValue', row.draInsureMoney)
                            $('#draCommisionMoney').numberbox('setValue', row.draCommisionMoney)
                            $('#draCommisionCurrency').combobox('setValue', row.draCommisionCurrency)
                            $('#draSeaCurrency').combobox('setValue', row.draSeaCurrency)
                            $('#draIsPlanAccounting').combobox('setValue', row.draIsPlanAccounting)
                            $('#draInsureCurrency').combobox('setValue', row.draInsureCurrency)
                            $('#draCreateOrderFlag').combobox('setValue', row.draCreateOrderFlag)
                            $('#draCurrencyTrade').combobox('setValue', row.draCurrencyTrade), $('#draPurchaseOrg').textbox('setValue', row.draPurchaseOrg)
                            $('#draSupply').textbox('setValue', row.draSupply)
                            $('#draSupplyId').val(row.draSupplyCode)
                            $('#draSettleFlag').combobox('setValue', row.draSettleFlag)
                            $('#draWeighFlag').combobox('setValue', row.draWeighFlag)
                            $('#draPackUp').combobox('setValue', row.draPackUp)
                            $('#draPaymentName').combobox('setValue', row.draPaymentId)
                            $('#draSaleAreaCode').combobox('setValue', row.draSaleAreaCode)
                            $('#draTerminologyForeignTradeName').combobox('setValue', row.draTerminologyForeignTradeCode)
                            $('#draProceedsName').combobox('setValue', row.draProceedsCode)
                            // $('#draPackAgeTotalCost').numberbox('setValue', row.draPackageTotalCost)
                            $('#draTransportTotalCost').numberbox('setValue', row.draTransportTotalCost)
                            $('#draPurchaseTotalAmount').numberbox('setValue', row.draPurchaseTotalAmount)
                            $('#draPurchaseTotalCount').numberbox('setValue', row.draPurchaseTotalCount)
                            $('#classificationDescr').combobox('setValue', row.classification)
                            $('#draPlanCompleteDeliveryTime').datetimebox('setValue', row.draPlanCompleteDeliveryTime)
                            // $('#classificationDescr').textbox('setValue', row.classificationDescr)
                            // 取得附件列表
                            getFileList(row)
                            productModelsTemp = row.productModels
                            if (row.draTypeId == '1') {
                                loadProductList([...productColumns, ...tradeColumns], productModelsTemp)
                            } else {
                                loadProductList(productColumns, productModelsTemp)
                            }

                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
                $('#add').window('open');
                $('#tabs').tabs('select', 0);
            }

            // 编辑/详情赋值
            function setDraftDetail(index) {
                const rows = $('#dg').datagrid('getRows');
                let draRow = rows[index];
                if ('1' != draRow.status) {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                save('save');
                            }
                        }, {
                            text: '提交',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            save('submit')
                                        }
                                    });
                            }
                        }]
                    })
                } else {
                    $('#tabs').tabs({
                        tools: null
                    })
                }
                // 编辑时不得弹出选择框
                $('#selectDraftWindow').window({
                    onBeforeOpen: function () {
                        return false
                    }
                })
                let draId = draRow.draId
                $('#draId').val(draId)
                // $('#fm').form('load', row);
                // 取得合同详细
                ajaxGetDetailByDraId(draId, 'detail')
            }

            // 编辑
            function editrow(draRow) {
                //编辑
                if (!draRow) {
                    $.messager.alert('消息', '请选中一条数据');
                    return
                }
                if ('1' == draRow.status) {
                    $.messager.confirm('提示', '该数据已提交，不可再次编辑。')
                    return
                }
                let index = $('#dg').datagrid('getRowIndex', draRow);
                setDraftDetail(index)
            }

            // 提交
            function commit(obj) {
                obj.status = '1'
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: 'sale/contract/draft/save',
                    data: JSON.stringify(obj),
                    contentType: "application/json",
                    success: function (data) {
                        $.messager.alert('消息', data.msg);
                        if (data.code != 60200) {
                        } else {
                            let dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load');
                            $('#add').window('close');
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            // 初始化长约合同列表
            function bindgrid() {
                let startTime = $('#startTime').datebox('getValue')
                let endTime = $('#endTime').datebox('getValue')
                let status = $('#status').combobox('getValue')
                $('#dg').datagrid(
                    {
                        title: '',
                        queryParams: {
                            startTime: startTime ? startTime : '',
                            endTime: endTime ? endTime : '',
                            status: status,
                            longTerm: '1'
                        },
                        url: "sale/contract/draft/selectList",
                        iconCls: 'icon-application',
                        width: getWidth(0.98),
                        height: 400,
                        filterDelay: 0,
                        nowrap: true,
                        rownumbers: true,
                        animate: false,
                        collapsible: false,
                        clientPaging: false,
                        remoteFilter: true,
                        singleSelect: true,
                        pagination: true,
                        remoteSort: true,
                        columns: [
                            [
                                {
                                    field: 'status',
                                    title: '状态',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        let status = val ? val : '';
                                        return unescape(status == '0' ? '待提交' : (status == '2' ? '已完成' : '已提交'));
                                    }
                                }, {
                                    field: 'draId',
                                    title: '合同起草id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draCode',
                                    title: '合同编号',
                                    sortable: true,
                                    formatter: function (val, rec, index) {
                                        return '<a href="javascript:void(0)" onclick="setDraftDetail(' + index +
                                            ')">' + (val ? val : '') + '</a>'
                                    }
                                }, {
                                    field: 'draName',
                                    title: '合同名称',
                                    sortable: true,
                                    formatter: function (val, rec, index) {
                                        return '<a href="javascript:void(0)" onclick="setDraftDetail(' + index +
                                            ')">' + (val ? val : '') + '</a>'
                                    }
                                }, {
                                    field: 'draMoney',
                                    title: '合同金额',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draTax',
                                    title: '税率',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                },
                                {
                                    field: 'oldDraCode',
                                    title: '原虚拟合同编号',
                                    sortable: true,
                                    formatter: function (val, rec, index) {
                                        return val ? unescape(val) : '';
                                    }
                                },
                                {
                                    field: 'oldDraId',
                                    title: '原虚拟合同id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec, index) {
                                        return val ? unescape(val) : '';
                                    }
                                },
                                {
                                    field: 'draTransportId',
                                    title: '运输方式id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draTransportName',
                                    title: '运输方式',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, /*{
                        field: 'draIsIn',
                        title: '是否内贸',
                        sortable: true,
                        formatter: function (val, rec) {
                            return unescape(val) == '1' ? '是' : '否';
                        }
                    },*/ {
                                    field: 'draSettleId',
                                    title: '结算方式代码',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draSettleName',
                                    title: '结算方式名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draPackageMoney',
                                    title: '包装费',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draTransportMoney',
                                    title: '运输总价',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                },/* {
                        field: 'draDays',
                        title: '账期',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    },*/ {
                                    field: 'draPaymentId',
                                    title: '付款方式id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draPaymentName',
                                    title: '付款条件',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'infCode',
                                    title: '客商编码',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'infName',
                                    title: '客商名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'infLegalPerson',
                                    title: '客商法定代表人',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'infHandlePerson',
                                    title: '客商代办人',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'longTerm',
                                    title: '是否长约',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val == '1' ? '是' : '否';
                                    }
                                }, {
                                    field: 'draTypeId',
                                    title: '合同类型id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draTypeName',
                                    title: '合同类型',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draSignTime',
                                    title: '合同签订日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draStartTime',
                                    title: '合同起始日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draEndTime',
                                    title: '合同终止日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'oaUserId',
                                    title: 'oa用户id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'oaWfId',
                                    title: 'oa流程id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'daCurrency',
                                    title: '币种',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draSeaMoney',
                                    title: '海运费',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'draRate',
                                    title: '汇率',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, /*{
                        field: 'draAgreementId',
                        title: '收付款协议id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'draAgreementName',
                        title: '收付款协议',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    },*/ {
                                    field: 'createTime',
                                    title: '创建时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createName',
                                    title: '创建人',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createId',
                                    title: '创建人id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateId',
                                    title: '更新id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateName',
                                    title: '更新人',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateTime',
                                    title: '更新时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'remark',
                                    title: '备注',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }]],
                        toolbar: [
                            {
                                text: '增加',
                                iconCls: 'icon-add',
                                handler: function () {
                                    addDraft();
                                }
                            },
                            '-',
                            {
                                text: '编辑',
                                iconCls: 'icon-edit',
                                handler: function () {
                                    let row = $('#dg').datagrid(
                                        'getSelected');
                                    if (row) {
                                        // $('#fm').form('load', row);
                                        editrow(row)

                                    }
                                }
                            },
                            '-',
                            {
                                text: '删除',
                                iconCls: 'icon-cancel',
                                handler: function () {
                                    var row = $('#dg').datagrid(
                                        'getSelected');
                                    if (row) {
                                        if ('1' == row.status) {
                                            $.messager.confirm('提示',
                                                '该合同已提交，无法删除?')
                                            return
                                        }
                                        $.messager.confirm('提示',
                                            '确定要删除这个吗?', function (r) {
                                                if (r) {
                                                    del(row);
                                                }
                                            });
                                    } else {
                                        $.messager.confirm('提示',
                                            '确定要删除该合同吗?')
                                        return
                                    }
                                }
                            },
                            '-',
                            {
                                text: '撤回',
                                iconCls: 'icon-undo',
                                handler: function () {
                                    var row = $('#dg').datagrid(
                                        'getSelected');
                                    if (row) {
                                        if ('1' != row.status) {
                                            $.messager.alert('提示', '该合同未提交，无需撤回')
                                            return
                                        }
                                        $.messager.confirm('提示',
                                            '确定要撤回该合同吗?', function (r) {
                                                if (r) {
                                                    backupDraft(row);
                                                }
                                            });
                                    } else {
                                        $.messager.confirm('提示',
                                            '请选择要撤回的合同')
                                        return
                                    }
                                }
                            }
                        ],
                        onLoadSuccess: function () {
                        }
                    }
                );
                $('#dg').datagrid('enableFilter');
            }

            /**
             *合同起草撤回
             */
            function backupDraft(draftObj) {
                $.ajax({
                    type: 'post',
                    url: 'sale/contract/draft/backLongTerm',
                    data: JSON.stringify(draftObj),
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            $.messager.alert('消息', data.msg)
                            let dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load');
                        } else {
                            $.messager.alert('消息', data.msg)
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })
            }

            // 查询已签署的合同列表
            function setchDraftsDataGrid() {
                // 构建查询合同起草的dataGrid
                let startTime = $('#startDraftTime').datebox('getValue')
                let endTime = $('#endDraftTime').datebox('getValue')
                let draftListDataGrid = $('#draftList')
                draftListDataGrid.datagrid({
                    queryParams: {
                        startTime: startTime ? startTime : '',
                        endTime: endTime ? endTime : '',
                        status: '1',
                        //transedSap: '1',
                        draVirtual: '1'
                    },
                    url: "sale/contract/sign/selectList",
                    iconCls: 'icon-application',
                    width: 810,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    clientPaging: false,
                    remoteFilter: true,
                    singleSelect: true,
                    pagination: true,
                    remoteSort: true,
                    columns: [
                        [{
                            field: 'draId',
                            title: '合同起草id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draCode',
                            title: '合同编号',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return val ? unescape(val) : '';

                            }
                        }, {
                            field: 'draName',
                            title: '合同名称',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return val ? unescape(val) : '';

                            }
                        }, {
                            field: 'draMoney',
                            title: '合同金额',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTax',
                            title: '税率',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportId',
                            title: '运输方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportName',
                            title: '运输方式name',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draIsIn',
                            title: '是否内贸',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSettleId',
                            title: '结算方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSettleName',
                            title: '结算方式name',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPackageMoney',
                            title: '包装费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTransportMoney',
                            title: '运输单价',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draDays',
                            title: '账期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPaymentId',
                            title: '付款方式id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draPaymentName',
                            title: '付款方式name',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infCode',
                            title: '客商编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infName',
                            title: '客商名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infLegalPerson',
                            title: '客商法定代表人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'infHandlePerson',
                            title: '客商代办人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTypeId',
                            title: '合同类型id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draTypeName',
                            title: '合同类型name',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSignTime',
                            title: '合同签订日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draStartTime',
                            title: '合同起始日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draEndTime',
                            title: '合同终止日期',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'oaUserId',
                            title: 'oa用户id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'oaWfId',
                            title: 'oa流程id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'daCurrency',
                            title: '币种',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draSeaMoney',
                            title: '海运费',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draRate',
                            title: '汇率',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draAgreementId',
                            title: '收付款协议',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'draAgreementName',
                            title: '收付款协议',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createTime',
                            title: '创建时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createName',
                            title: '创建人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'createId',
                            title: 'create_id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateId',
                            title: 'update_id',
                            sortable: true,
                            hidden: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateName',
                            title: '更新人',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'updateTime',
                            title: '更新时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'delFlag',
                            title: 'del_flag',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }, {
                            field: 'status',
                            title: '状态',
                            sortable: true,
                            formatter: function (val, rec) {
                                return +val == '1' ? unescape('已提交') : '待提交';
                            }
                        }, {
                            field: 'remark',
                            title: '备注',
                            sortable: true,
                            formatter: function (val, rec) {
                                return val ? unescape(val) : '';
                            }
                        }
                        ]
                    ],
                    toolbar: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: function () {
                            let row = $('#draftList').datagrid('getSelected')
                            if (!row) {
                                $.messager.alert('提示', '请选择一条数据')
                                return
                            }
                            ajaxGetDetailByDraId(row.draId, 'add')
                            $('#selectDraftWindow').window('close')
                        }
                    }],
                    onLoadSuccess: function () {

                    }
                }
                )
                draftListDataGrid.datagrid('enableFilter');
            }

            /************文件处理部分*************/

            /**
             * 保存附件
             */

            function saveAttch(row, obj, action) {
                obj.draId = row
                let saveNum = 0
                if (selectedFileList.length > 0) {
                    $.each(selectedFileList, function (index, item) {
                        load();
                        var dataform = new FormData();
                        dataform.append("file", item);
                        var xmlhttp = null;
                        if (window.XMLHttpRequest) { // code for all new browsers
                            xmlhttp = new XMLHttpRequest();
                        } else if (window.ActiveXObject) {// code for IE5 and IE6
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        if (xmlhttp != null) {
                            xmlhttp.open("POST", "api/file/springUpload?fileRow=" + row
                                + "&fileTable=sale_contract_draft&fileName="
                                + item.name, true);
                            xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                            xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                            xmlhttp.send(dataform);
                            xmlhttp.onreadystatechange = callbackMethods;
                        } else {
                            alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                        }

                        function callbackMethods() {
                            if (xmlhttp.readyState == 4) {
                                if (xmlhttp.status == 200) {
                                    saveNum += 1
                                }
                                if (saveNum == selectedFileList.length) {
                                    disLoad();
                                    if ('submit' == action) {
                                        commit(obj)

                                    }
                                }
                            } else {
                                if (xmlhttp.status == 500) {
                                }
                            }
                        }
                    });

                } else {
                    if ('submit' == action) {
                        commit(obj)
                    }
                }
            }

            /**
             *文件框改变事件
             */
            function changeFile() {
                var files = $("#uploadpicker").prop("files");
                $.each(
                    files,
                    function (index, item) {
                        let choiseFile = $("#checkfileList>li");
                        if (choiseFile.length > 0) {//文件去重
                            let count = 0;
                            $.each(choiseFile, function (index1, item1) {
                                if (item.name == item1.innerText) {
                                    count++;
                                }
                            });
                            if (count == 0) {
                                if (checkFileLength(item.size)) {
                                    if (item.name.includes('&') || item.name.includes(' ')) {
                                        alert('文件名不能包含&、空格等特殊字符！');
                                        return;
                                    }
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + item.name
                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + item.name
                                            + "')\">删除</a>"
                                            + "</li>");
                                    selectedFileList.push(item);
                                    AddMoushover();
                                }
                            }
                        } else {
                            if (checkFileLength(item.size)) {
                                if (item.name.includes('&') || item.name.includes(' ')) {
                                    alert('文件名不能包含&、空格等特殊字符！');
                                    return;
                                }
                                $("#checkfileList")
                                    .append(
                                        "<li class=\"fileinfo\">"
                                        + item.name
                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                        + item.name
                                        + "')\">删除</a>"
                                        + "</li>");
                                selectedFileList.push(item);
                                // 										sselectedFileNameList.push(item.name);
                                AddMoushover();
                            }
                        }
                    });
            }

            /**
             *    判断文件是否超过限制大小
             * @param fileLen
             * @returns {boolean}
             */
            function checkFileLength(fileLen) {
                if (fileLen > 102400000) {
                    $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                    return false;
                }
                return true;
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”
             * @constructor
             */
            function AddMoushover() {
                $(".fileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             *  移除已选择的文件
             */

            function RemoveFile(obj, fileId) {

                $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                    if (e) {
                        let index = $("#checkfileList>li").index($(obj).parent());
                        selectedFileList.splice(index, 1);
                        $(obj).parent().remove();

                        $.ajax({
                            type: "post",
                            url: 'file/deleteFile?fileId=' + fileId,
                            success: function (data) {
                                $.messager.alert('消息', data);
                            },
                            error: function (XMLHttpRequest, textStatus,
                                errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        });
                    }
                });
            }

            /**
             * 取得该条数据所属的文件列表
             * @param row
             */
            function getFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "sale_contract_draft",
                        fileRow: row.draId
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initFile(dataArray, row.status);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 初始化该条数据的文件列表
             * @param dataArray
             */
            function initFile(dataArray, status) {
                $("#checkfileList").empty();
                selectedFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#checkfileList")
                            .append(
                                "<li class=\"fileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + "</a>"
                                + (status > 0 ? '' : "</a>"
                                    + "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                    + e.FILE_ID + "')\">删除</a>")
                                + "</li>");
                        if (status > 0) {
                        } else {
                            AddMoushover();
                        }
                    });
            }

            function downloadFile(fileName, fileRow) {
                let url = 'api/file/download?id=' + fileRow
                let xhr = new XMLHttpRequest()
                xhr.open('GET', url, true)
                xhr.setRequestHeader('token', localStorage.getItem('token'));
                xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                xhr.responseType = 'blob'
                xhr.onload = function (data) {
                    if (this.status == 200) {
                        let blob = this.response
                        let reader = new FileReader()
                        reader.readAsDataURL(blob)
                        reader.onload = function (e) {
                            let a = document.createElement('a')
                            a.download = fileName
                            a.href = e.target.result
                            $('body').append(a)
                            a.click()
                            $(a).remove()
                        }
                    } else {
                    }
                }
                xhr.send()
            }

            // 判断产品是否需要获取远期定价
            function queryProductCodeWhetherNeedGetForward(productCode) {
                let flag = false
                let params = {
                    dicValue: productCode,
                    dicName: '远期基准价产品列表'
                }
                $.ajax({
                    type: 'post',
                    async: false,
                    url: 'sale/contract/draft/productCodeWhetherNeedGetForward',
                    data: JSON.stringify(params),
                    dateType: 'json',
                    contentType: "application/json",
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.responseJSON.code != 60200) {
                            $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                        } else {
                            let result = XMLHttpRequest.responseJSON.data
                            if (result != null) {
                                flag = true
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        disLoad();
                        $.messager.alert('消息', errorThrown);
                    }
                })
                return flag
            }
        </script>

        </html>